package com.zhs.smartmall.member.service.impl;


import com.zhs.smartmall.member.model.UmsMemberLoginLog;
import com.zhs.smartmall.member.dao.UmsMemberLoginLogDao;
import com.zhs.smartmall.member.service.IUmsMemberLoginLogService;
import com.zhs.smartmall.member.dto.UmsMemberLoginLogDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class UmsMemberLoginLogServiceImpl extends ServiceImpl< UmsMemberLoginLogDao, UmsMemberLoginLog> implements IUmsMemberLoginLogService {

    @Resource
    private UmsMemberLoginLogDao umsMemberLoginLogDao;

    @Override
    @Transactional
    public R addOrUpdate(UmsMemberLoginLogDto umsMemberLoginLogDto) {
        if (BeanUtil.isEmpty(umsMemberLoginLogDto)) throw new ServiceException("数据不能为空");
        UmsMemberLoginLog umsMemberLoginLog = new UmsMemberLoginLog();
        BeanUtil.copyProperties(umsMemberLoginLogDto,umsMemberLoginLog);
        if (umsMemberLoginLogDto.getId() == null){
            umsMemberLoginLogDao.insert(umsMemberLoginLog);
            return R.ok("数据插入成功");
        }else {
            umsMemberLoginLogDao.updateById(umsMemberLoginLog);
            return R.ok("数据更新成功");
        }
    }
}